package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.ItemService;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@Tag(name = "专辑详情管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class itemApiController {

    @Autowired
    private ItemService itemService;

    @Autowired
    private SearchService searchService;


    /**
     * 根据关键词检索
     *
     * @param queryVo
     * @return
     * @throws IOException
     */
    @Operation(summary = "专辑搜索列表")
    @PostMapping("/albumInfo")
    public Result search(@RequestBody AlbumIndexQuery queryVo) throws IOException {
        //  调用服务层方法.
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(queryVo);
        return Result.ok(albumSearchResponseVo);
    }

    /**
     * 根据id查询专辑的详细信息
     * /api/search/albumInfo/{albumId}
     */
    @Operation(summary = "根据id查询专辑的详细信息")
    @GetMapping("/albumInfo/{albumId}")
    public Result<Map> getItem(@PathVariable Long albumId) {
        Map<String,Object> map = itemService.getItem(albumId);
        return Result.ok(map);
    }

}

